package com.eric.windows.anima;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;

import com.eric.windows.R;

/**
 * <h3>Description</h3>
 * TODO
 * <h3>Author</h3> Eric
 * <h3>Date</h3> 2017/7/28 17:29
 * <h3>Copyright</h3> Copyright (c)2017 Shenzhen TLIT  Co., Ltd. Inc. All rights reserved.
 */
public class CircleAnim  extends View {
    private float mPivotX;
    private float mPivotY;
    private float mRadius;
    private Paint mPaint;

    public CircleAnim(Context context) {
        this(context, null);
    }

    public CircleAnim(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public CircleAnim(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);

        TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.CircleAnim);
        mPivotX = ta.getDimension(R.styleable.CircleAnim_pivotX, 0);
        mPivotY = ta.getDimension(R.styleable.CircleAnim_pivotY, 0);
        mRadius = ta.getDimension(R.styleable.CircleAnim_radius, 0);
        ta.recycle();

        init();
    }

    private void init() {
        mPaint = new Paint();
        mPaint.setAntiAlias(true);
        mPaint.setStrokeWidth(5);
        mPaint.setColor(Color.parseColor("#0F000F"));
    }

    public void setRadius(float radius) {
        mRadius = radius;
        invalidate();
    }

    public float getRadius() {
        return mRadius;
    }

    @Override
    protected void onDraw(Canvas canvas) {
        canvas.drawCircle(mPivotX, mPivotY, mRadius, mPaint);
        super.onDraw(canvas);
    }
}

